package xyz.migle.sc.demo;

import org.apache.commons.lang.StringUtils;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Configuration;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Configuration
@ServletComponentScan
@WebFilter(urlPatterns = "/*",filterName = "firstfilter")
public class FirstFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        String userId = request.getParameter("user_id");
       // System.out.println("在这里拦截请求");
        if(StringUtils.isBlank(userId)){
         //   System.out.println("在这里判断逻辑");
        }
        HttpServletRequest hreq = (HttpServletRequest) request;
        System.out.println("这里是需要过滤的！！！！" + hreq.getRequestURI());
        System.out.println("这里是需要过滤的！！！！" + hreq.getRemoteAddr());
        System.out.println("这里是需要过滤的！！！！" + hreq.getRemoteHost());
        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}
